<template>
  <div class="warning">
    <el-card class="box-card card" style="padding: 10px;">
      <div class="login-img" style="cursor: pointer" @click="back">
        <img src="~@/assets/family.png"/>
      </div>
      <p class="login-welcome">注册家庭账号</p>
      <el-form v-if="check=='first'">
        <div class="login-btn">
          <el-button v-loading="loading" class="btn" @click="creat()">注册家庭账号</el-button>
        </div>
        <div class="login-btn">
          <el-button v-loading="loading" class="btn" @click="join()">加入家庭</el-button>
        </div>
      </el-form>
      <el-form style="margin-top: 30px" v-else-if="check=='join'">
        <el-form-item>
          <el-input
              type="text"
              v-model="family_Num"
              placeholder="家庭账号"
              autocomplete="off"
          ></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button v-loading="loading" class="btn" @click="joinFamily()">加入家庭</el-button>
        </div>
      </el-form>
      <el-form style="margin-top: 30px" v-else-if="check=='creat'">
        <el-form-item>
          <el-input
              type="text"
              v-model="family_name"
              placeholder="家庭名"
              autocomplete="off"
          ></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button v-loading="loading" class="btn" @click="creatFamily()">创建家庭账号</el-button>
        </div>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "Warning",
  data: function () {
    return {
      formCustom: {
        phone: "",
        password: "",
      },
      loading: false,
      check: 'first',
      family_Num: "",
      family_name: ""
    }
  },
  mounted() {
  },
  methods: {
    joinFamily() {
      let that = this
      this.$http.post("/login/joinFamily", {family_Num: that.family_Num}).then(data => {
        //console.log(data)
        if (data.code == 200) {
          this.$message.success("加入成功")
          this.$router.push("/login")
        }
      })
    },
    creatFamily() {
      this.$http.post("/login/registerFamily", {name: this.family_name}).then(data => {
        //console.log(data)
        if (data.code == 200) {
          this.$message.success("创建成功")
          this.$router.push("/login")
        }
      })
    },
    join() {
      this.check = 'join'
    },
    back() {
      this.check = 'first'
    },
    creat() {
      this.check = 'creat'
    }
  }
}
</script>

<style scoped>
.warning {
  height: 100vh;
  background: linear-gradient(
      270deg, rgb(229, 226, 219), rgba(125, 166, 227, 0.5), rgba(220, 67, 67, 0.5));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.card {
  width: 300px;
  height: 300px;
  /*position: absolute;*/
  /*top: 50%;*/
  /*left: 50%;*/
  /*transform: translate(-50%, -50%);*/
}

.login-img {
  /*width: 60%;*/
  height: 50px;
  border-radius: 20px;
  border: 1px dashed #eaeaea;
}

img {
  height: 100%;
  /*width: 100%;*/
}

p {
  text-align: center;
  color: #51cacc;
  line-height: 30px;
  margin-bottom: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  margin-top: 15px;
}

.btn {
  width: 100%;
  height: 40px;
  background-image: -webkit-gradient(linear, right top, left top, from(rgba(142, 239, 252, .9)), to(rgba(142, 197, 252, .6)));
  background-image: linear-gradient(
      270deg, rgba(142, 239, 252, .9), rgba(142, 197, 252, .6));
  color: #fff;
  margin: 20px 0;
}

a {
  color: #51cacc;
  font-weight: 500;
  text-decoration: none;
  -webkit-transition: all .6s;
  transition: all .6s;
  position: relative;
  -webkit-transition: all .6s ease-in-out;
  transition: all .6s ease-in-out;
}

.user {
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 5px
}
</style>